<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java"%>
<%@ page import="java.util.Locale"%>
<%@ page import="java.text.NumberFormat"%>
<%@ page import="net.ge.mosq.service.impl.AccountServiceImpl"%>
<%@ page import="net.ge.mosq.service.AccountService"%>
<%@ page import="net.ge.mosq.service.ServiceFactory"%>
<%@ page import="net.ge.mosq.jdo.entity.AccountItem"%>
<%@ page import="java.util.List"%>
<%@ page import="javax.jdo.PersistenceManager"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="com.google.appengine.api.datastore.Entity"%>
<%@ page import="net.ge.mosq.utils.JspUtility"%>
<%-- <%@ include file="/taglibs.jsp" %> --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<!-- <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" /> -->
<link type="text/css" rel="stylesheet" href="/stylesheets/jquery.treeTable.css" />
<script type="text/javascript" src="/js/jquery.treeTable.js"></script>
<script type="text/javascript">
<!--
	$(document).ready(function() {
		$("#main-table").treeTable({
		    initialState: "expanded"
		});
	});
	function transaction(_id) {
		var aForm = document.createElement('form');
		aForm.action = '/A001.html';
		aForm.method = 'post';
		aForm.innerHTML = '<input name="CurrentAccId" type="hidden" value="' + _id + '" />';
		aForm.innerHTML = aForm.innerHTML
				+ '<input name="ActionFlg" type="hidden" value="0" />';
		aForm.submit();
	}
//-->
</script>
</head>
<body>
 <fmt:setBundle basename="ApplicationResource" scope="page" var="default" />
      
      <fmt:formatNumber value="12345.67" type="currency" />
  <form action="" method="post"></form>
  <table id="main-table" style="margin-left: 10px; border: 1px solid #999;">
    <thead>
      <tr>
        <th>NAME</th>
        <th>TYPE</th>
        <th>CODE</th>
        <th><fmt:message key="description" bundle="${default}"/></th>
        <th><fmt:message key="total" bundle="${default}"/></th>
        <th><fmt:message key="placeholder" bundle="${default}"/></th>
      </tr>
    </thead>
    <tbody>
      <%
      	AccountService as = new AccountServiceImpl();
      	List<AccountItem> items = as.getAllAccountWithTransInfoFlat("common");
      	NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.CHINA);
      	for (AccountItem acc : items) {
      		if (acc.getParentId() == null) {
      			out.print("<tr id=\"n-" + acc.getId() + "\">");
      		} else {
      			out.print("<tr id=\"n-" + acc.getId() + "\" class=\"child-of-n-" + acc.getParentId() + "\">");
      		}
      %>
      <%--       <td style="padding-left: <%=acc.getLevel() * 20%>px"> --%>
      <td>
      <%if(!"true".equalsIgnoreCase(acc.getPlaceholder())) {%>
      <a href="javascript:return false;" title="<%=acc.getName()%>" onclick="javascript:transaction('<%=acc.getId()%>');" draggable="true"> <%=acc.getName()%></a>
      <%} else {%>
      <%=acc.getName()%>
      <%}%>
      </td>
      <td><%=acc.getType()%></td>
      <td><%=acc.getCode()%></td>
      <td><%=acc.getDescription()%></td>
      <td><%=nf.format(acc.getTransactionSum())%></td>
      <td><input type="checkbox" disabled="disabled" <%if("true".equalsIgnoreCase(acc.getPlaceholder())) out.write("checked=\"checked\"");%> /></td>
      </tr>
      <%
      	}
      %>
    </tbody>
  </table>
</body>
</html>